#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# author: maxiao
# date: 2023-05-30 15:56
# description: 实现测试参数化

import unittest

from parameterized import parameterized
import ddt


class Base(unittest.TestCase):
    """测试类的基类"""

    def setUp(self):
        """前置工作"""
        print("测试开始")

    def tearDown(self):
        """清理工作"""
        print("测试结束")


class TestAdd(Base):
    """计算器加法测试"""

    data = [[1, 2, 3], [4, 5, 9], [11, 9, 21]]
    @parameterized.expand(data)
    def test_add(self, a, b, c):
        self.assertEqual(a+b, c, msg='加法结果有误！')

@ddt.ddt
class TestMul(Base):
    """计算器乘法测试"""
    
    data = [[3, 0, 0], [3, 5, 15], [-1, 5, -5], [-1, -3, 3]]
    @ddt.data(*data)
    def test_mul(self, row):
        self.assertEqual(row[0] * row[1], row[2], msg="乘法结果有误！")

if __name__ == "__main__":
    unittest.main(verbosity=2)

